<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .hd {
      border: solid 2px #ddd;
      background-color: red;
      color: white;
    }
  </style>
<body>
    <ul>
        <li>houdunren.com</li>
        <li>hdcms.com</li>
      </ul>
    <script>
        //下面是为父级UL设置事件来控制子元素LI的样式切换
          'use strict'
  const ul = document.querySelector('ul')
  ul.addEventListener('click', () => {
      console.log(event.target.tagName );//tagName元素的大写(LI)
      //使用toggle切换类，即类已经存在时删除，不存在时添加
    if (event.target.tagName=="LI") event.target.classList.toggle('hd');
  
  })
    </script>
</body>
</html>